package com.deerblock.config;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.graphics.Color;
import android.os.Build;
import android.view.View;
import android.widget.Toast;

import com.deerblock.LoginActivity;
import com.deerblock.R;
import com.umeng.umverify.UMVerifyHelper;
import com.umeng.umverify.listener.UMCustomInterface;
import com.umeng.umverify.view.UMAbstractPnsViewDelegate;
import com.umeng.umverify.view.UMAuthRegisterViewConfig;
import com.umeng.umverify.view.UMAuthRegisterXmlConfig;
import com.umeng.umverify.view.UMAuthUIConfig;


public class DialogBottomConfig extends BaseUIConfig {

  public DialogBottomConfig(Activity activity, UMVerifyHelper authHelper) {
    super(activity, authHelper);
  }

  @Override
  public void configAuthPage() {
    mAuthHelper.removeAuthRegisterXmlConfig();
    mAuthHelper.removeAuthRegisterViewConfig();
    int authPageOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT;
    if (Build.VERSION.SDK_INT == 26) {
      authPageOrientation = ActivityInfo.SCREEN_ORIENTATION_BEHIND;
    }
    updateScreenSize(authPageOrientation);
    int dialogHeight = (int) (mScreenHeightDp * 0.5f);
    //sdk默认控件的区域是marginTop50dp
    int designHeight = dialogHeight - 50;
    int unit = designHeight / 10;
    int logBtnHeight = (int) (unit * 1.2);
    mAuthHelper.addAuthRegistViewConfig("switch_msg", new UMAuthRegisterViewConfig.Builder()
      .setView(initSwitchView(unit * 6))
      .setRootViewId(UMAuthRegisterViewConfig.RootViewId.ROOT_VIEW_ID_BODY)
      .setCustomInterface(new UMCustomInterface() {
        @Override
        public void onClick(Context context) {
          Toast.makeText(mContext, "切换到其他登录方式", Toast.LENGTH_SHORT).show();
          Intent pIntent = new Intent(mActivity, LoginActivity.class);
          mActivity.startActivityForResult(pIntent, 1002);
          mAuthHelper.quitLoginPage();
        }
      })
      .build());
    mAuthHelper.addAuthRegisterXmlConfig(new UMAuthRegisterXmlConfig.Builder()
      .setLayout(R.layout.custom_auth, new UMAbstractPnsViewDelegate() {
        @Override
        public void onViewCreated(View view) {
          findViewById(R.id.btn_close).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              mAuthHelper.quitLoginPage();
            }
          });
        }
      })
      .build());

    mAuthHelper.setAuthUIConfig(new UMAuthUIConfig.Builder()
      .setAppPrivacyOne("《自定义隐私协议》", "https://www.baidu.com")
      .setAppPrivacyColor(Color.GRAY, Color.parseColor("#002E00"))
      .setWebViewStatusBarColor(Color.TRANSPARENT)

      .setNavHidden(true)
      .setSwitchAccHidden(true)
      .setPrivacyState(false)
      .setCheckboxHidden(true)

      .setLogoImgPath("mytel_app_launcher")
      .setLogoOffsetY(0)
      .setLogoWidth(42)
      .setLogoHeight(42)

      .setNumFieldOffsetY(unit + 10)
      .setNumberSizeDp(17)

      .setSloganText("为了您的账号安全，请先绑定手机号")
      .setSloganOffsetY(unit * 3)
      .setSloganTextSizeDp(11)

      .setLogBtnOffsetY(unit * 4)
      .setLogBtnHeight(logBtnHeight)
      .setLogBtnMarginLeftAndRight(30)
      .setLogBtnTextSizeDp(20)
      .setLogBtnBackgroundPath("login_btn_bg")

      .setPageBackgroundPath("dialog_page_background")
      .setAuthPageActIn("in_activity", "out_activity")
      .setAuthPageActOut("in_activity", "out_activity")
      .setVendorPrivacyPrefix("《")
      .setVendorPrivacySuffix("》")
      .setDialogHeight(dialogHeight)
      .setDialogBottom(true)
      .setScreenOrientation(authPageOrientation)
      .create());
  }
}
